/**
 * Created by YY on 7/19/2016.
 */
angular.module('login', ['ui.router'])
  .config(function ($stateProvider) {
    $stateProvider.state('login', {
        url: "/login",
        templateUrl: "app/login/login.html",
        controller: 'LoginCtrl'
      }
    )
  })
  .controller('LoginCtrl', function ($scope, $http, $location, login, setCredit) {
    $scope.username = '';
    $scope.password = '';
    $scope.login = function () {
      login($scope.username, $scope.password, function (error, res) {
        if (error !== null) {
          console.log(error);
        } else {
          setCredit(res.data);
          var type = res.data.type;
          if (type == 7) {
            $location.path('/admin');
          } else if (type == 1) {
            $location.path('/student');
          } else if (type == 2) {
            $location.path('/teacher/qa');
          }
        }
      });
    }
  });

